package br.inatel.ec203.projeto.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class RadioButtonPanel extends JPanel {

	private static final long serialVersionUID = -8247775931952201716L;
	
	private RadioButtonsListeners radioButtonsListeners;

	private JRadioButton componentRadioButton;
	private JRadioButton partNumberRadioButton;
	
	public RadioButtonPanel() {
		
		initialize();
	}

	private void initialize() {
		add(getComponentRadioButton());
		add(getPartNumberRadioButton());
	}

	public JRadioButton getComponentRadioButton() {
		if (componentRadioButton == null) {
			componentRadioButton = new JRadioButton();
			componentRadioButton.setText("Pesquisar por valor de componente");
			componentRadioButton.setSelected(false);			
			componentRadioButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					radioButtonsListeners.componentPerformed();
					getPartNumberRadioButton().setSelected(false);
				}
			});
		}
		return componentRadioButton;
	}

	public JRadioButton getPartNumberRadioButton() {
		if (partNumberRadioButton == null) {
			partNumberRadioButton = new JRadioButton();
			partNumberRadioButton.setText("Pesquisar por Part Number");			
			partNumberRadioButton.setSelected(false);
			partNumberRadioButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					radioButtonsListeners.partNumberPerformed();
					getComponentRadioButton().setSelected(false);
				}
			});
		}
		return partNumberRadioButton;
	}	
	
	public void addRadioButtonsListeners(
			RadioButtonsListeners radioButtonsListeners) {
		this.radioButtonsListeners = radioButtonsListeners;
	}
}
















